package com.baobao.web.rest;

import com.baobao.dao.AskleaveDAO;

import com.baobao.domain.Askleave;

import com.baobao.service.AskleaveService;

import java.util.Calendar;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for Askleave entities
 * 
 */

@Controller("AskleaveRestController")
public class AskleaveRestController {

	/**
	 * DAO injected by Spring that manages Askleave entities
	 * 
	 */
	@Autowired
	private AskleaveDAO askleaveDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Askleave entities
	 * 
	 */
	@Autowired
	private AskleaveService askleaveService;

	/**
	 * Delete an existing Askleave entity
	 * 
	 */
	@RequestMapping(value = "/Askleave/{askleave_parentPhone}/{askleave_studentId}/{askleave_applyTime}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteAskleave(@PathVariable String askleave_parentPhone, @PathVariable String askleave_studentId, @PathVariable Calendar askleave_applyTime) {
		Askleave askleave = askleaveDAO.findAskleaveByPrimaryKey(askleave_parentPhone, askleave_studentId, askleave_applyTime);
		askleaveService.deleteAskleave(askleave);
	}

	/**
	 * Save an existing Askleave entity
	 * 
	 */
	@RequestMapping(value = "/Askleave", method = RequestMethod.PUT)
	@ResponseBody
	public Askleave saveAskleave(@RequestBody Askleave askleave) {
		askleaveService.saveAskleave(askleave);
		return askleaveDAO.findAskleaveByPrimaryKey(askleave.getParentPhone(), askleave.getStudentId(), askleave.getApplyTime());
	}

	/**
	 * Create a new Askleave entity
	 * 
	 */
	@RequestMapping(value = "/Askleave", method = RequestMethod.POST)
	@ResponseBody
	public Askleave newAskleave(@RequestBody Askleave askleave) {
		askleaveService.saveAskleave(askleave);
		return askleaveDAO.findAskleaveByPrimaryKey(askleave.getParentPhone(), askleave.getStudentId(), askleave.getApplyTime());
	}

	/**
	 * Select an existing Askleave entity
	 * 
	 */
	@RequestMapping(value = "/Askleave/{askleave_parentPhone}/{askleave_studentId}/{askleave_applyTime}", method = RequestMethod.GET)
	@ResponseBody
	public Askleave loadAskleave(@PathVariable String askleave_parentPhone, @PathVariable String askleave_studentId, @PathVariable Calendar askleave_applyTime) {
		return askleaveDAO.findAskleaveByPrimaryKey(askleave_parentPhone, askleave_studentId, askleave_applyTime);
	}

	/**
	 * Show all Askleave entities
	 * 
	 */
	@RequestMapping(value = "/Askleave", method = RequestMethod.GET)
	@ResponseBody
	public List<Askleave> listAskleaves() {
		return new java.util.ArrayList<Askleave>(askleaveService.loadAskleaves());
	}

	/**
	 * Register custom, context-specific property editors
	 * 
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}
}